package com.yz.design.factoryDesign.simpleFactory;


public class PayFactory {
    public static final String ALI_PAY = "ali";
    public static final String WX_PAY = "wx";
    public static final String UNION_PAY = "union";

    /**
     * @param payMethod 支付方式
     * @return
     */
    public static Pay getPayObj(String payMethod) {
        Pay pay = null;
        if (payMethod.equals(ALI_PAY)) {
            pay = new AliPay();
        } else if (payMethod.equals(WX_PAY)) {
            pay = new WxPay();
        } else if (payMethod.equals(UNION_PAY)) {
            pay = new UnionPay();
        } else {
            // 其他支付方式不支持，可在此记录错误日志
        }
        return pay;
    }


}

///**
// * 利用反射解决简单工厂每次增加新了产品类都要修改产品工厂的弊端
// */
//class PayFactory2 {
//    public static Object getClass(Class<? extends Pay> clazz) {
//        Object obj = null;
//
//        try {
//            obj = Class.forName(clazz.getName()).newInstance();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//        return obj;
//    }
//}